/* Copyright 2007 Gearbox Software - http://www.gearboxsoft.com
 
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at
 
     http:www.apache.org/licenses/LICENSE-2.0
 
 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.*/
using System;
using System.Collections.Generic;
using System.Text;

namespace GearBlog.UnitTests
{
	using GearBlog.Web.Models;
	using NUnit.Framework;

	[TestFixture]
	public class UserRoleTestCase:AbstractTestCase
	{
		[Test]
		public void UserCreateTest1()
		{
			User user = CreateUser();
			user.Save();
			user.Refresh();
			ObjectMother.Flush();
		}
		[Test]
		public void RoleCreateTest1()
		{
			Role role = CreateRole();
			ObjectMother.Flush();

		}
		private static Role CreateRole()
		{
			Role role = ObjectMother.Create<Role>();
			role.Name = "admin role";
			role.Save();
			return role;
		}
		private static User CreateUser()
		{
			User user = ObjectMother.Create<User>();
			user.UserName = "testuser";
			user.FullName = "Test User";
			user.Password = "password";
			user.SetPasswordHash();

			return user;
		}

		[Test]
		public void UserRoleCreateTest1()
		{
			User user = CreateUser();
			Role role = CreateRole();
			user.Roles.Add(role);
			user.Save();

			user.Refresh();

			foreach (Role userRole in user.Roles)
			{
				Assert.AreEqual(role.Name, userRole.Name);
			}
			Assert.AreEqual(1,user.Roles.Count);
			ObjectMother.Flush();
		}


	}
}
